<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_adhj_call_t {
        background-color: #254060;
        height: 444px;
        color: white;
        overflow: auto;
    }

    .pa_andon_call {
        margin-top: 5%;
        height: 60px;
        line-height: 60px;
        width: 70%;
        margin-left: 20%;
        text-align: center;
    }

    .pa_adhj_call_but {
        height: 58px;
        line-height: 58px;
        float: left;
        width: 150px;
        font-size: 25px;
        color: white;
        margin-left: 50px;
        text-align: center;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟安创</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:24%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>安灯呼叫</p>
            </div>
        </div>
        <div class="aui-flex-col aui-flex-center">
            <div class="aui-flex-item-12 pa_adhj_call_t">
                <div class="aui-flex-col">
                    <div class="aui-flex-item-12">
                        <div class="aui-flex-col pa_andon_call">
                            <div class="aui-list-item-inner" style="border: 0;">
                                <div class="aui-list-item-label" style="font-size: 25px;float: left;">
                                    异常类型：</div>
                                <div class="aui-list-item-input" style="background-color: white;float: left;">
                                    <select id="exceptionType" onchange="onChange()" style="width: 300px;">
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="aui-flex-col pa_andon_call">
                            <div class="aui-list-item-inner" style="border: 0;">
                                <div class="aui-list-item-label" style="font-size: 25px;float: left;">
                                    异常内容：</div>
                                <div class="aui-list-item-input" style="background-color: white;float: left;">
                                    <select id="exceptionContent" style="width: 300px;">
                                        <option value=''>--请选择--</option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="aui-flex-col pa_andon_call">
                            <div class="aui-list-item-inner" style="border: 0;">
                                <div class="aui-list-item-label" style="font-size: 25px;float: left;">
                                    备&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp注：</div>
                                <div class="aui-list-item-input"
                                    style="background-color: white;float: left;width: 300px;">
                                    <input type="text" id="remark" class="aui-input" onclick="getIdSelector();" />
                                </div>
                            </div>
                        </div>

                        <div class="aui-flex-col pa_andon_call">
                            <div class="pa_adhj_call_but" style="background-color: #4B7902;" onclick="save()">
                                提交
                            </div>
                            <div class="pa_adhj_call_but" style="background-color: #D9001B;" onclick="cancle()">
                                关闭
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";
    //光标所在id
    var idSelector = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);

        //查询异常类型下拉框
        doSearchExceptionType();

    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //查询异常类型下拉框
    function doSearchExceptionType() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: {
                tablename: "usm_exception_type",
                column_name: "name",
                column_value: "sysid",
                condition: "is_delete=0",
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                    }

                    $api.html($api.byId("exceptionType"), html);
                } else {
                    $api.html($api.byId("exceptionType"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //异常类型值改变
    function onChange() {
        var exceptionTypeId = $("#exceptionType").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: {
                tablename: "usm_exception_content",
                column_name: "name",
                column_value: "sysid",
                condition: "exception_type_gid= '" + exceptionTypeId + "'",
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                    }

                    $api.html($api.byId("exceptionContent"), html);
                } else {
                    $api.html($api.byId("exceptionContent"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //呼叫保存
    function save() {
        var exceptionTypeId = $("#exceptionType").val();
        var exceptionContentId = $("#exceptionContent").val();
        var remark = $("#remark").val();
        if (exceptionTypeId == null || exceptionTypeId == "" || exceptionTypeId == undefined) {
            api.toast({
                msg: '请选择异常类型！',
                duration: 3000
            });
            return;
        }

        if (exceptionContentId == null || exceptionContentId == "" || exceptionContentId == undefined) {
            api.toast({
                msg: '请选择异常内容！',
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyAndonCall";
        var data = {
            values: {
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: api.pageParam.workCellCode,
                exceptionTypeId: exceptionTypeId,
                exceptionContentId: exceptionContentId,
                remark: remark,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });
                    cancle();
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //取消按钮
    function cancle() {
        api.closeWin({});
        api.execScript({
            name: 'productionAssemblyAndon',
            script: 'refresh()'
        });
    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>